package com.test;

import java.util.Random;
import java.util.Scanner;

public class main {
    public static void main(String[] args) throws NoZeroException, LessZeroException {
        int a,b,c;
        int flag = 1;
        random random = new random();
        mathing mathing = new mathing();
        decide decide = new decide();
        grace1 grace1 = new grace1();
        grace3 grace3 = new grace3();
        score score = new score();
        System.out.println("测试开始");
        do {
            System.out.printf("请选择下一步操作");
            System.out.println("1:一年级（加减）,3:三年级（四则）,0:退出测试");
            Scanner scanner = new Scanner(System.in);
            int inside = scanner.nextInt();
            switch (inside){
                case 1:
                    for (int i = 1;i<11;i++){
                        System.out.println("第"+i+"次计算");
                        double[] array =random.randomnumber();//接收生成的随机数组
                        int tmp = grace1.random(array[0],array[1]);//判断运算法则
                        try{
                            decide.decide(array[0],array[1],tmp);
                        }catch (LessZeroException lessZeroException){
                            System.out.println("本题运算结果为负数");
                            System.out.println("任意输入后继续");
                        }catch (NoZeroException noZeroException){
                            System.out.println("本题除数为0");
                            System.out.println("任意输入后继续");
                        }
                        Scanner scanner1 = new Scanner(System.in);
                        int inside1 = scanner1.nextInt();//接收用户输入
                        double answer =mathing.mathtwo(array[0],array[1],tmp);//输出正确答案
                        score.score(decide.input(inside1,answer));
                        if (i ==10){
                            System.out.println("测试结束,最终得分为"+score.score);
                        }
                    }
                    break;
                case 3:
                    for (int i = 1;i<11;i++){
                        System.out.println("第"+i+"次计算");
                        double[] array =random.randomnumber();//接收生成的随机数组
                        int tmp = grace3.random(array[0],array[1]);//判断运算法则
                        try{
                            decide.decide(array[0],array[1],tmp);
                        }catch (LessZeroException lessZeroException){
                            System.out.println("本题运算结果为负数");
                            System.out.println("任意输入后继续");
                        }catch (NoZeroException noZeroException){
                            System.out.println("本题除数为0");
                            System.out.println("任意输入后继续");
                        }
                        Scanner scanner1 = new Scanner(System.in);
                        int inside1 = scanner1.nextInt();//接收用户输入
                        double answer =mathing.mathfour(array[0],array[1],tmp);//输出正确答案
                        score.score(decide.input(inside1,answer));
                        if (i ==10){
                            System.out.println("测试结束,最终得分为"+score.score);
                        }
                    }
                    break;
                case 0:
                    System.out.print("感谢参与\n");
                    flag = 0;
                    break;
                default:
                    System.out.print("输入错误，请重新选择\n");
            }
            //选择系统参考
        }while (flag == 1);

    }
}
class random{
    double[] randomnumber() {
        Random random = new Random();
        int a = random.nextInt(100);
        int b = random.nextInt(100);
        double[] arraylist = {a, b};
        for(int i =0;i<arraylist.length;i++){
            System.out.println(arraylist[i]+",");
        }
        return arraylist;
        //生成数组,生成随机两个数
    }
}

class mathing {
    double mathtwo(double a,double b,int c){
        System.out.println("运算中");
        double tmp = 0;
        switch (c) {
            case 0:
                tmp = a + b;
                System.out.println("本题答案为" + tmp);
                break;
            case 1:
                tmp = a - b;
                System.out.println("本题答案为" + tmp);
                break;
        }
        return tmp;
    }
    int mathfour(double a,double b,int c){
        System.out.println("运算中");
        double tmp = 0;
        switch (c) {
            case 0 :
                tmp = a + b;
                System.out.println("本题答案为" + tmp);
                break;
            case 1 :
                tmp = a - b;
                System.out.println("本题答案为" + tmp);
                break;
            case 2 :
                tmp = a * b;
                System.out.println("本题答案为" + tmp);
                break;
            case 3 :
                tmp = a / b;
                System.out.println("本题答案为" + (tmp%2.d));
                break;
        }
        return (int)tmp;
    }
}
class LessZeroException extends Exception{
    //处理结果不为负数异常
    public LessZeroException(){
         super();
    }
    public LessZeroException(String message){
        super(message);
    }
}

class NoZeroException extends Exception{
    //除数不能为零异常
    public NoZeroException(){
        super();
    }
    public NoZeroException(String message){
        super(message);
    }
}
